﻿@{
    ViewData["Title"] = "文件上传与下载";
}

<div class="container-fixed-md">
    <div class="row">
        <div class="col-lg-10">
            <form class="form-horizontal" method="post" id="uploadFileTest" enctype="application/x-www-form-urlencoded">
                <div class="form-group">
                    <div class="col-lg-10">
                        <input type="file" class="form-control" id="File" name="File">
                    </div>
                </div>

                <div class="form-group" style="margin-top:15px;">
                    <div class="col-lg-10">
                        <button type="button" id="btn_Post" class="btn btn-default">上传文件</button>
                    </div>
                </div>

            </form>
        </div>
        <div class="col-lg-10">

           文件下载地址: <div id="downloadUrlTest"></div>
        </div>
        <div class="col-lg-10">

            <a href="#" id="downloadFileTest" target="_blank">我是文件下载(点击上面的上传文件并且提醒成功以后就可以测试文件下载了)</a>
        </div>
    </div>
</div>
@section Scripts{
    <script src="~/lib/jquery/jquery.form.js"></script>

    <script type="text/javascript">
        $("#btn_Post").click(function () {
            $("#uploadFileTest").ajaxSubmit({
                url: '/File/Upload',
                success: function (res) {
                    alert('文件上传成功');
                    $("#downloadUrlTest").text(res);
                    $("#downloadFileTest").attr("href", "/file/download?file=" + res);
                }
            });
        });
    </script>
}

